Skip to content

Add interface generation#143

Draft
adamhathcock wants to merge 2 commits intoDevTeam:devfrom
adamhathcock:adam/di-interface
Draft

Add interface generation#143
adamhathcock wants to merge 2 commits intoDevTeam:devfrom
adamhathcock:adam/di-interface

Conversation

@adamhathcock
Copy link
Copy Markdown

Starts to address #142

This pull request introduces a new source generator to automatically create interfaces from annotated classes in the Pure.DI project. It adds the ability to customize the generated interface's namespace, name, and access level, and to selectively ignore class members. The implementation is supported by comprehensive integration and usage tests covering generics, member exclusion, and customization scenarios.

Core: Interface Generation Feature

  • Added a new InterfaceGenerator source generator (InterfaceGenerator.cs) that generates interfaces for classes annotated with [GenerateInterface], with support for customizing the namespace, interface name, and access modifier. It also registers the necessary attribute sources.
  • Implemented logic for extracting interface generation details and attribute parameters in GeneratedInterfaceDetails.cs.
  • Added Roslyn extensions for member and type constraint extraction to support interface generation.
  • Integrated the interface generator into the main SourceGenerator, including syntax provider registration and attribute detection logic. [1] [2] [3]

Supporting Attributes

  • Added attribute source code for [GenerateInterface] and [IgnoreInterface] via RegisterInterfaceAttributesExtensions.cs, enabling users to mark classes and members for inclusion/exclusion in generated interfaces.

Testing & Usage Examples

  • Added integration tests (InterfaceGenerationTests.cs) to verify interface generation, member exclusion, and Pure.DI integration.
  • Added usage scenario tests demonstrating:
    • Basic interface generation and Pure.DI usage (GenerateInterfaceScenario.cs)
    • Excluding members from interfaces with [IgnoreInterface] (IgnoreInterfaceScenario.cs)
    • Generics, events, and nullable annotations in generated interfaces (GenerateInterfaceGenericsScenario.cs)
    • Customizing interface name, namespace, and accessibility (GenerateInterfaceCustomizationScenario.cs)

@adamhathcock
Copy link
Copy Markdown
Author

Currently working on
image

@adamhathcock adamhathcock marked this pull request as draft April 21, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant